#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<queue>
#include<algorithm>

using namespace std;


namespace zy
{
	template<class T>
	struct less
	{
		bool operator()(const T& x, const T& y)
		{
			return x < y;
		}
	};

	template<class T>
	struct greater
	{
		bool operator()(const T& x, const T& y)
		{
			return x > y;
		}
	};


	template<class T, class Container = vector<T>, class Compare = less<T>>
	class priority_queue
	{
	public:
		bool empty()
		{
			return _con.empty();
		}
		size_t size()
		{
			return _con.size();
		}

		void swap(T& x, T& y)
		{
			T tmp = x;
			x = y;
			y = tmp;
		}

		void adjust_up(size_t child)
		{
			Compare com;
			size_t parent = (child - 1) / 2;
			while (child > 0)
			{
				//if (_con[parent] < _con[child])
				if (com(_con[parent], _con[child]))
				{
					swap(_con[parent], _con[child]);
					child = parent;
					parent = (child - 1) / 2;
				}
				else
					break;
			}
		}

		void push(const T& val)
		{
			_con.push_back(val);
			adjust_up(_con.size() - 1);
		}

		void adjust_down()
		{
			size_t parent = 0;
			size_t child = 2 * parent + 1;
			Compare com;
			while (child < _con.size())
			{
				//if (child + 1 < _con.size() && _con[child + 1] > _con[child])
				//if (child + 1 < _con.size() && _con[child] < _con[child + 1])
				if (child + 1 < _con.size() && com(_con[child], _con[child + 1]))
				{
					child++;
				}
				//if (_con[parent] < _con[child])
				if (com(_con[parent] , _con[child]))
				{
					swap(_con[parent], _con[child]);
					parent = child;
					child = 2 * parent + 1;
				}
				else
					break;
			}
		}

		void pop()
		{
			swap(_con[0], _con[_con.size() - 1]);
			_con.pop_back();
			adjust_down();
		}
		T& top()
		{
			return _con[0];
		}

	private:
		Container _con;
	};
}

